package com.yxw.live_vod_boot.controller;


import com.yxw.live_vod_boot.dto.fans.ShopFollowQueryDTO;
import com.yxw.live_vod_boot.dto.follow.*;
import com.yxw.live_vod_boot.service.FansService;
import com.yxw.live_vod_boot.service.FollowService;
import com.yxw.live_vod_boot.vo.*;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author fangmaoxin
 * &#064;date  2023年11月21日
 */
@Slf4j
@RestController
@Api(value = "关注页接口", tags = "关注页")
@RequestMapping("/api/follow")
public class FollowController {

    @Autowired
    private FollowService followService;

    @Autowired
    private FansService fansService;

    /**
     * 用户侧-查询自己的关注列表
     */
    @PostMapping("/getFollowListByUserId")
    @ApiOperation("用户侧--展示自己的关注列表")
    public BaseResult<PageVO<FollowListVO>> list(@RequestParam("userId") Long userId, @RequestBody @Validated FollowQueryDTO dto) {
        PageVO<FollowListVO> list = followService.getFollowListByUserId(userId, dto);
        return ResultHelper.fillWithSuccess(list);
    }

    /**
     * 店铺侧-查询自己的关注列表
     */
    @PostMapping("/getShopFollowListByShopId")
    @ApiOperation("店铺侧--查询自己的关注列表")
    public BaseResult<PageVO<ShopFollowListVO>> getShopFollowListByShopId(@RequestParam("shopId") Long shopId, @RequestBody @Validated ShopFollowQueryDTO dto) {
        PageVO<ShopFollowListVO> list = fansService.getShopFollowListByShopId(shopId, dto);
        return ResultHelper.fillWithSuccess(list);
    }

    /**
     * 用户侧-新朋友列表
     */
    @PostMapping("/newFriendListForUser")
    @ApiOperation("用户侧-新朋友列表")
    public BaseResult<PageVO<NewFriendListVO>> list(@RequestParam("userId") Long userId, @RequestBody @Validated NewFriendQueryDTO dto) {
        PageVO<NewFriendListVO> list = followService.getNewFriendList(userId, dto);
        return ResultHelper.fillWithSuccess(list);
    }

    /**
     * 店铺侧-新朋友列表
     */
    @PostMapping("/newFriendListForShop")
    @ApiOperation("店铺侧-新朋友列表")
    public BaseResult<PageVO<NewFriendListVO>> list(@RequestParam("userId") Long userId, @RequestBody @Validated ShopNewFriendQueryDTO dto) {
        PageVO<NewFriendListVO> list = followService.getShopNewFriendList(userId, dto);
        return ResultHelper.fillWithSuccess(list);
    }

    /**
     * 用户新增一个关注
     */
    @PostMapping("/insertFollowByUserId")
    @ApiOperation("用户新增一个关注")
    public BaseResult insertFollowByUserId(@RequestParam("userId") Long userId, @RequestBody @Validated FollowAddDTO dto) {
        return BaseResult.doSuccess(followService.insertFollowByUserId(userId, dto), "关注成功！");
    }

    /**
     * 用户取消一个关注
     */
    @PostMapping("/deleteFollowByUserId")
    @ApiOperation("用户取消一个关注")
    public BaseResult deleteFollowByUserId(@RequestBody @Validated FollowDeleteDTO dto) {
        return BaseResult.doSuccess(followService.deleteFollowByUserId(dto), "取关成功！");
    }

    /**
     * 查询自己有没有关注某个用户/店铺
     */
    @PostMapping("/checkFollowStateForUser")
    @ApiOperation("查询自己有没有关注某个用户/店铺")
    public BaseResult<FollowStateVO> checkFollowStateForUser(@RequestParam("userId") Long userId, @RequestBody @Validated FollowStateQueryDTO dto) {
        FollowStateVO result = followService.checkFollowStateForUser(userId, dto);
        return BaseResult.doSuccess(result, "操作成功！");
    }
}
